package org.mushroomdb.parser.sql92.impl.util;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import org.mushroomdb.catalog.Column;
import org.mushroomdb.catalog.EncodeableRegister;
import org.mushroomdb.catalog.Register;
import org.mushroomdb.catalog.Table;

public class CorrelatedTable implements Table {

	private Table innerTable;
	private String correlationName;
	private ArrayList correlatedColumns;
	
	public CorrelatedTable(Table table) {
		this.innerTable = table;
		this.correlationName = this.innerTable.getName();
		this.constructCorrelatedColumns();
	}
	
	private void constructCorrelatedColumns() {
		this.correlatedColumns = new ArrayList();
		Iterator columnIterator = this.innerTable.getColumns();
		while (columnIterator.hasNext()) {
			this.correlatedColumns.add( new CorrelatedColumn( (ColumnInterface)columnIterator.next(), this ) );
		}
	}
	
	public void setColumnCorrelation(int index, String name) { 
		((CorrelatedColumn)this.correlatedColumns.get(index)).setName(name);
	}

	public String getName() {
		return this.correlationName;
	}

	public void setName(String name) {
		this.correlationName = name;
	}

	public Iterator getColumns() {
		return this.correlatedColumns.iterator();
	}

	public void addColumn(Column column) {
		//do nothing
	}

	public Column getColumn(String name) {
		Iterator iterator = this.correlatedColumns.listIterator();
		while (iterator.hasNext()) {
			Column column = (Column) iterator.next();
			if (column.getName().equals(name)) {
				return column;
			}
		}
		return null;
	}

	public Iterator getRegisters() {
		return (new LinkedList()).iterator();
	}

	public Iterator getPages() {
		return (new LinkedList()).iterator();
	}

	public void insertRegister(EncodeableRegister register) {
		// do nothing
	}

	public boolean deleteRegister(Register register) {
		//do nothing
		return false;
	}

	public long getRegisterCount() {
		return this.innerTable.getRegisterCount();
	}

}
